#pragma once
#ifndef Image_H
#define Image_H

#include "Matrix.h"
#include <QImage>
#include "sobel_filter.h"

class Image : public Matrix
{
public:
    operator QImage()
    {
        int length;
                length = width*height*3%4!=0 ? (width*height*3 * 24 / 8 + 3) / 4 * 4 / 3: width*height*3;
        unsigned char * d = new unsigned char [length];
        for (int i = 0; i < height; i++)
        for (int j = 0; j < width; j++)
        for (int rgb = 0; rgb < 3; rgb++)                  //   3*height*width   data[0][0][0]  -> data[height - 1][j][2]
            d[(height- 1 - i)*width*3+ j*3+ 2- rgb] = data[i][j][rgb];
        return QImage(d,width,height,QImage::Format_RGB888);
    }

    Image& operator = (const Image& m)
    {
        this->Matrix::operator =(m);
        return *this;
    }

    Image& operator = (const double a)
    {
        this->Matrix::operator = (a);
        return *this;
    }

    void to_barrel();
    void operator +(int m);
    void warm_cold_change(double m);
    void gray2bw(double t);
    void Rotate_Left();
    void Rotate_Right();
    void Turned_Over();
    void operator -();
    void Frequent(const char* filename, double***& data, int& height, int& width);
    Image();
    Image(int h, int w);
    Image(const char* ImageName);
    Image(double* m, int h, int w);
    Image(const Matrix& m);
    Image(const Image& im);
    Image(const Sobel& sobel);
    virtual ~Image();

    void ReadBMP(const char* ImageName);
    void WriteBMP(const char* filename);

    void Flip(int code);
    void Resize(int h, int w);
    void Cut(int x1, int y1, int x2, int y2);
    void gray();
    void choose();
    friend Image sobel(Image input);
    Sobel turn_to_sobel();

    enum Type{edge = 0,middle,core};
};
#endif
